package com.jswlw.controller.api.wrapper;

import com.jswlw.common.ResponseStatus;
import com.jswlw.controller.api.resp.DistributorListResponse;
import com.jswlw.entity.biz.Distributor;
import com.jswlw.service.biz.DistributorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 吴维斌 E-mail:wuweibin0817@163.com
 * @version 创建时间：${date} ${time}
 */
@Component
public class DistributorWrapper {
    @Autowired
    DistributorService distributorService;

    public DistributorListResponse distributorList() {
        DistributorListResponse response = new DistributorListResponse();
        Distributor filter = new Distributor();
        List<Distributor> list = distributorService.queryList(filter);
        List<DistributorListResponse.DistributorListData> data = new ArrayList<>();
        list.forEach(distributor -> {
            data.add(DistributorListResponse.DistributorListData.builder()
                    .parentId(0)
                    .value(String.valueOf(distributor.getId()))
                    .name(distributor.getName())
                    .build());
        });

        response.setData(data);
        response.setCode(ResponseStatus.SUCCESS.getCode());
        response.setMsg(ResponseStatus.SUCCESS.getMsg());
        return response;
    }
}
